﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;

namespace DAO
{
    public class LoaiSanPhamDAO: DataAccess
    {
        public LoaiSanPham CreateObj(DataRow row)
        {
            LoaiSanPham obj = new LoaiSanPham();
            obj.MaLoaiSP = Utils.ToStr(row["MaLoaiSP"]);
            obj.TenLoaiSP = Utils.ToStr(row["TenLoaiSP"]);
            return obj;
        }
        public List<LoaiSanPham> GetList()
        {
            DataTable tb = GetData("EXEC GetData ?", "@TableNameX", "LoaiSanPham", OleDbType.VarChar);
            List<LoaiSanPham> LstLoaiSanPham = new List<LoaiSanPham>();
            for (int i = 0; i < tb.Rows.Count; i++)
            {
                LstLoaiSanPham.Add(CreateObj(tb.Rows[i]));
            }
            return LstLoaiSanPham;
        }
        public bool Insert(LoaiSanPham obj)
        {
            obj.MaLoaiSP = Utils.ToStr(InsertData("EXEC InsertLoaiSanPham ?", CommandType.Text,
                                   "@TenLoaiSP", obj.TenLoaiSP, OleDbType.VarWChar));
            if (obj.MaLoaiSP != null)
                return true;
            else
                return false;
        }
        public bool Update(LoaiSanPham obj)
        {
            return UpdateDeleteData("EXEC UpdateLoaiSanPham ?, ?", CommandType.Text,
                                   "@MaLoaiSP", obj.MaLoaiSP, OleDbType.VarChar,
                                   "@TenLoaiSP", obj.TenLoaiSP, OleDbType.VarWChar);

        }
        public bool Delete(LoaiSanPham obj)
        {
            return UpdateDeleteData("EXEC DeleteLoaiSanPham ?", CommandType.Text, "@MaLoaiSP", obj.MaLoaiSP, OleDbType.VarChar);
        }
    }
}
